package cj.web.sc.controllers;

import java.util.List;

import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.var.Model;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import cj.web.constants.MemuEnum;
import cj.web.sc.dao.SCAddressDAO;
import cj.web.sc.dao.MemberDAO;
import cj.web.sc.domain.SCAddress;
import cj.web.sc.domain.Member;

@Path("/scaddress")
public class SCAddressController{

	private static Logger logger = Logger.getLogger(SCAddressController.class.getName());
	
	@Autowired
	private SCAddressDAO addressDao;
	
	@Autowired
	private MemberDAO buyerDao;

	@Get("show")
	public String show(Model model,@Param("buyerId")int buyerId,SCAddress address)
	{
		model.add("buyerId",buyerId);
		Member obj = buyerDao.queryById(buyerId);
		model.add("phone",obj.getPhone());
		model.add("MemuEnum", MemuEnum.hyg);
		return "/views/sc/addressList.vm";
	}
	
	@Post("list")
	public String list(Model model,SCAddress address)
	{
		List<SCAddress> objs = addressDao.queryByBuyerId(address);
		int size = addressDao.sizeByBuyerId(address);
		
		JSONObject jo = new JSONObject();
		jo.put("data", objs);
		jo.put("draw", address.getDraw());
		jo.put("recordsTotal", size);
		jo.put("recordsFiltered", size);
		return "@" + jo.toString();
	}
}
